﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

class bugData : senses
{
    public int oldHp = 0;
    public int hp = 100;
    public string id = "";
    public int group = 0;
    public int changed = 0;
    public List<Neuron> plus = new List<Neuron>();

    public void AddNeuron(bugData me)
    {
       
        
        this.AddNeuron(me.network);
    }

    public void AddNeuron(List<Neuron> nn)
    {
        plus = new List<Neuron>();
 
        foreach (Neuron tmp in nn)
        {
            Predicate<Neuron> pd
            = new Predicate<Neuron>(
                delegate(Neuron mes)
                {
                    return mes.wdo == tmp.wdo && mes.key == tmp.key;
                });
            ;
            if (network.Find(pd) == null)
            {
                plus.Add(tmp);
            }
            else
            {
                network.Find(pd).trust++;
            }
        }

        network.AddRange(plus);
    }

    public List<Neuron> getNeuron()
    {
        return network;
    }

    public void AddNeuronSuccess()
    {
        List<Neuron> nn = this.getNeuron();
        Neuron n = new Neuron();
        n.trust++;
        n.key = ((int)(this.oldHp / 10) * 10).ToString();
        doTop[] lst = this.getLists();
        if (lst.Length > 0)
        {

            n.wdo = lst[lst.Length - 1];
        }

        Predicate<Neuron> pd
            = new Predicate<Neuron>(
                delegate(Neuron mes)
                {
                    return mes.wdo == n.wdo && mes.key == n.key;
                });

        if (nn.Find(pd) != null)
        {
            Neuron temp = nn.Find(pd);
            Debug.Message("[OLD]" + nn.Find(pd).trust + ":" + temp.key + ":" + temp.wdo.doName);
            temp.trust++;
            Debug.Message("[OUT]" + nn.Find(pd).trust + ":" + temp.key + ":" + temp.wdo.doName);
            Debug.Message("");
        }
        else
        {

            this.network.Add(n);
        }
    }

    public bool goORstop()
    {
        return true;

    }

    public override string ToString()
    {
        string result = "";
        switch (group)
        {
            case 0: result= "N"; break;
            case 1: result = "W"; break;
            case 2: result = "E"; break;
            case 3: result = "A"; break;
            case 4: result = "K"; break;
            default: result = "N";  break;
        }
        return result;
    }

}
